package com.mall.service.impl;

import com.mall.common.utils.Security;
import com.mall.dao.custom.CtArticleMapper;
import com.mall.entity.Article;
import com.mall.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-02-25 17:42
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private CtArticleMapper articleMapper;


    @Override
    public int add(Article article) {
        article.setCreateTime(new Date());
        article.setCreateBy(Security.getCurrentUserId());
        return articleMapper.insert(article);
    }

    @Override
    public int modify(Article article) {
        article.setUpdateBy(Security.getCurrentUserId());
        article.setUpdateTime(new Date());
        return articleMapper.updateByPrimaryKeySelective(article);
    }

    @Override
    public int remove(Integer articleId) {
        return articleMapper.deleteByPrimaryKey(articleId);
    }

    @Override
    public int increasePageView(Integer articleId) {
        return articleMapper.updatePageViewIncrease(articleId);
    }

    @Override
    public List<Article> list(String keyWord) {
        return articleMapper.selectList(keyWord);
    }

    @Override
    public Article get(Integer articleId) {
        return articleMapper.selectByPrimaryKey(articleId);
    }
}
